package titt.io.encoding;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;

import titt.type.Type;

public class ObjectDecoder implements Decoder {

	@Override
	public Object decode(Type t, byte[] b) {
		
		ByteArrayInputStream bin = new ByteArrayInputStream(b);
		
		try {
			ObjectInputStream ois = new ObjectInputStream(bin);			
			return ois.readObject();
		}
		catch(Exception e) {
			return null;
		}
	}

	@Override
	public boolean isDecodeable(Type t) {
		return t.isNative();
	}

}
